/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/
#ifndef TRACKPOINT_H
#define TRACKPOINT_H

#include "IncFreeTrack.h"

class TrackPoint
{
public:
    // ... from date, position, precision and speed
    TrackPoint(QGeoCoordinate &coord, QDateTime time, qreal precision, qreal speed);
    // ... from XML stream
    TrackPoint(QXmlStreamReader*);
    // ... from another point
    TrackPoint(const TrackPoint&);
    // ... from a QPointF
    TrackPoint(const QPointF&);
    // ... empty!
    TrackPoint();

    ~TrackPoint();

    // Conversion to QPointF (lon, lat)
    operator QPointF() const;

    // get/set precision
    qreal getPrecision() const;
    void setPrecision(qreal);
    // get/set timestamp
    QDateTime getTimestamp() const;
    // get/set speed
    qreal getSpeed() const;

    // Draw the point on the TrackTable
    virtual QPoint draw(QPainter&, QColor, const QTransform&) const;

    // Convert to/from XML
    virtual void toGpx(QXmlStreamWriter* stream) const;
    virtual void fromGpx( QXmlStreamReader* stream );
    // Convert to/from pure TXT (for autosave or similar)
    virtual QString toTxt() const;
    virtual bool fromTxt( const QString& );

    // Some geometrical functions... calculate distance between two points
    qreal distanceFrom(const QPointF&) const;
    qreal distanceFrom(const QGeoCoordinate&) const;
    qreal distanceFrom(const TrackPoint&) const;

    // Check if two points do overlap (given precision)
    bool isOverlapping(const TrackPoint&) const;

protected:
    QDateTime timestamp;
    QPointF position;
    qreal precision;
    qreal precision_ll;
    qreal altitude;
    qreal speed;
    QString name;
    QString description;

    qreal convertM2LL(qreal) const;
    qreal convertLL2M(qreal) const;
};

#endif // TRACKPOINT_H
